const request = require("../requests");

// 获取登录 token
function getLoginToken(data) {
  return request.post("/index.php/api/index/getcode", data);
}

// 获取用户信息
function getUserInfo(data) {
  return request.get("/index.php/api/index/getcode", data);
}

// 获取 code
function getCode() {
  return new Promise((resolve) => {
    wx.login({
      success: (res) => {
        resolve(res.code);
      },
    });
  });
}

function getWxRunData(data) {
  return new Promise((resolve) => {
    wx.getWeRunData({
      success: (rundata) => {
        resolve({
          encryptedData: rundata.encryptedData,
          iv: rundata.iv,
        });
      },
      fail: (err) => {
        console.log(err);
      },
    });
  });
}

// 获取用户今日目标步数
function getTodayStep() {
  return request.get("/index.php/api/index/goal");
}

// 设置用户今日目标步数
function setTodayStep(data) {
  return request.post("/index.php/api/index/subgoal", data);
}


// 获取金刚区数据
function getJingang() {
  return request.get("/index.php/api/index/kong");
}

// 获取最新公告
function getNotice() {
  return request.get("/index.php/api/index/affiche");
}

// 获取轮播图
function getBanner() {
  return request.get("/index.php/api/index/banner");
}

// 获取日常活动
function getActivity() {
  return request.get("/index.php/api/index/routtines");
}

// 获取收货地址
function getAddress() {
  return request.get("/index.php/api/index/profile_me");
}

// 添加收货地址
function addAddress(data) {
  return request.post("/index.php/api/index/profile", data);
}

// 删除收货地址
function deleteAddress(data) {
  return request.post("/index.php/api/index/profile_delete", data);
}

// 编辑收货地址
function editAddress(data) {
  return request.post("/index.php/api/index/profile_edit", data);
}

// 导出
module.exports = {
  getLoginToken,
  getUserInfo,
  getCode,
  getWxRunData,
  getTodayStep,
  setTodayStep,
  getJingang,
  getNotice,
  getBanner,
  getActivity,
  getAddress,
  addAddress,
  deleteAddress,
  editAddress,
};
